package cn.iocoder.yudao.module.system.repository.mybatis.dao.permission;

import cn.iocoder.yudao.common.pojo.PageResult;
import cn.iocoder.yudao.core.mybatis.core.dataobject.Base;
import cn.iocoder.yudao.core.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.core.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.repository.mybatis.domain.permission.Role;
import cn.iocoder.yudao.module.system.vo.permission.role.RoleExportReqVO;
import cn.iocoder.yudao.module.system.vo.permission.role.RolePageReqVO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable;

import java.util.Collection;
import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapperX<Role> {

    default PageResult<Role> selectPage(RolePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<Role>()
                .likeIfPresent(Role::getName, reqVO.getName())
                .likeIfPresent(Role::getCode, reqVO.getCode())
                .eqIfPresent(Role::getStatus, reqVO.getStatus())
                .betweenIfPresent(Base::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(Role::getId));
    }

    default List<Role> selectList(RoleExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<Role>()
                .likeIfPresent(Role::getName, reqVO.getName())
                .likeIfPresent(Role::getCode, reqVO.getCode())
                .eqIfPresent(Role::getStatus, reqVO.getStatus())
                .betweenIfPresent(Base::getCreateTime, reqVO.getCreateTime()));
    }

    default Role selectByName(String name) {
        return selectOne(Role::getName, name);
    }

    default Role selectByCode(String code) {
        return selectOne(Role::getCode, code);
    }

    default List<Role> selectListByStatus(@Nullable Collection<Integer> statuses) {
        return selectList(Role::getStatus, statuses);
    }

}
